<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use App\Http\Resources\ProductCategorysResource;
use App\Http\Resources\ProductResource;
use App\Models\Product;
use App\Models\ProductCategory;
use Doctrine\DBAL\Schema\Schema;
use Illuminate\Http\Request;
use function JmesPath\search;

/**
 * Class CategoryController
 * 分类
 * @package App\Http\Controllers\Home
 */
class CategoryController extends Controller
{
    /**
     * Display a listing of the resource.
     *获取所有的分类
     * @param ProductCategory $category
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
     */
    public function index(ProductCategory $category)
    {
        $category=$category->getAllCategory();
        return  ProductCategorysResource::collection($category);
    }

    /**
     * 获取分类中的内容
     * @param ProductCategory $category
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
     */
    public  function  show(ProductCategory $category) {
        $product=Product::where('category_id',$category->id)->paginate(24);
        return ProductResource::collection($product);
    }

}
